/*
# File    :   list_app.c
# Author  :   SCHIPS
# Mail    :   schips@dingtalk.com
# Date    :   Tue, May 21, 2019  8:55:00 PM
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "list_app.h"


int remove_node_in_list(linknode *head, const char* client)
{
    int state = -1;
    linknode *rm_node;
    struct list_head *pos, *n;

    if(list_empty(&head->list))
    {
        return -1;
    }

    list_for_each_safe(pos, n, &head->list)
    {
        rm_node = list_entry(pos, linknode, list);
        // 判断条件
        if(strcmp(client,rm_node->info.client_name) == 0)
        {
            list_del(pos);
            free(rm_node);
            state = 0;
            break;
        }

    }

    return state;
}

int print_list(linknode * head)
{
    struct list_head *pos;
    linknode *my_list_p;

    if(list_empty(&head->list)) 
    {
        return -1;
    }

    list_for_each(pos, &head->list)
    {
        my_list_p = list_entry(pos, linknode, list);
        printf("%p\n", my_list_p->info.client_name);
    }
    return 0;
}


void destory_list(linknode *head)
{
    struct list_head *pos, *n;
    linknode *my_list_p;

    list_for_each_safe(pos, n, &head->list)
    {
        my_list_p = list_entry(pos, linknode, list);
        free(my_list_p);
    }
    free(head);
}

